package com.example.bpmn.controller;

import com.example.bpmn.event.ProcessEvent;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@Slf4j
@Tag(name = "事件接口")
@RestController
@RequestMapping("/api/events")
public class EventController {

    @Autowired
    private KafkaTemplate<String, ProcessEvent> kafkaTemplate;

    @Operation(summary = "发送业务事件")
    @PostMapping("/send")
    public ResponseEntity<Void> sendEvent(@RequestBody ProcessEvent event) {
        log.info("发送事件: {}", event);
        kafkaTemplate.send("process-events", event.getBusinessKey(), event);
        return ResponseEntity.ok().build();
    }
} 